<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>formdata</title>
    <script src="js/axios.min.js"></script>
</head>
<body>
<form id="form">
    <input type="text" name="username" placeholder="用户名">
    <input type="text" name="password" placeholder="密码">
    <input type="file" name="file" multiple>
    <button type="submit">提交</button>
</form>
<script>
  var form = document.getElementById('form')
  form.addEventListener('submit', function (e) {
    e.preventDefault()
    var formData = new FormData(form)
    //formData已经承载了所有我们要上传的数据
    //直接打印formData是看不到这些数据的需要打印 formData.getAll('标签里的name值')才能看到某一name下的全部内容
    // console.log('我是username，我在formData里承载', formData.getAll('username'))
    // console.log('我是password，我在formData里承载', formData.getAll('password'))
    // console.log('file，我在formData里承载', formData.getAll('file'))
    axios.post('http://localhost:4000/submit', formData).then(res => {
      console.log(res.data)
    })
  })
</script>
</body>
</html>
